#!/srv/newsblur/venv/newsblur3/bin/python

import os

from vendor.munin.cassandra import MuninCassandraPlugin


class CassandraPendingPlugin(MuninCassandraPlugin):
    title = "thread pool pending tasks"
    args = "--base 1000 -l 0"
    vlabel = "pending tasks"
    scale = False

    @property
    def fields(self):
        tpstats = self.tpstats()
        fs = []
        for name, stats in tpstats.items():
            fs.append((name.lower().replace('-', '_'), dict(
                    label = name,
                    info = name,
                    type = "GAUGE",
                    min = "0",
                )))
        return fs

    def execute(self):
        tpstats = self.tpstats()
        values = {}
        for name, stats in tpstats.items():
            values[name.lower().replace('-', '_')] = stats['pending']
        return values

if __name__ == "__main__":
    CassandraPendingPlugin().run()
